package cn.yangliu.service.impl;

import cn.yangliu.entity.Setting;
import cn.yangliu.jpa.base.service.impl.JpaServiceImpl;
import cn.yangliu.repository.SettingRepository;
import cn.yangliu.service.SettingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @author 问道于盲
 * @date 2021-09-28
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class SettingServiceImpl extends JpaServiceImpl<Setting, Long, SettingRepository> implements SettingService {

    /**
     * 判断配置是否存在
     *
     * @param name 配置名
     * @return 是否存在
     */
    @Override
    public boolean exist(String name) {
        return repository.existsByName(name);
    }

    /**
     * 根据配置名查询配置
     *
     * @param name 配置名
     * @param id 配置id
     * @return 配置信息
     */
    @Override
    public Optional<Setting> existNotEqualsId(String name, Long id) {
        return repository.existNotEqualsId(name, id);
    }
}
